package com.basiclib.utils

import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.FormatStrategy
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy


class L constructor(val tag: String, val isDebug: Boolean) {
    init {
        val formatStrategy = PrettyFormatStrategy.newBuilder()
            .showThreadInfo(true)  // (Optional) Whether to show thread info or not. Default true
            .methodCount(1)         // (Optional) How many method line to show. Default 2
            .methodOffset(2)        // (Optional) Hides internal method calls up to offset. Default 5
            .tag(tag)   // (Optional) Global tag for every log. Default PRETTY_LOGGER
            .build()
        Logger.addLogAdapter(CustomLogAdapter(formatStrategy))
    }

    inner class CustomLogAdapter(formatStrategy: FormatStrategy) : AndroidLogAdapter(formatStrategy) {
        override fun isLoggable(priority: Int, tag: String?): Boolean {
            return !isDebug
        }
    }

    companion object {
        @JvmStatic
        fun e(tag: String = "", msg: String) = Logger.t(tag).e(msg)

        @JvmStatic
        fun d(tag: String = "", msg: String) = Logger.t(tag).d(msg)

        @JvmStatic
        fun i(tag: String = "", msg: String) = Logger.t(tag).i(msg)

        @JvmStatic
        fun w(tag: String = "", msg: String) = Logger.t(tag).w(msg)
    }
}